package acm.pta11;

import java.util.Scanner;

public class 前世彩票 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        sc.nextLine();
        while (n-->0){
            char[] chars = sc.nextLine().toCharArray();
            int res=0;
            for (int i = 0; i < chars.length; i++) {
                if (chars[i]=='n'){
                    res+=1<<(m-i-1);
                }
            }
            System.out.println(res+1);
        }
    }
}
